﻿@{
    Layout = "~/Views/Shared/_Index.cshtml";
}
<div class="container-div">
    <div class="row">
        <div id="searchDiv" class="col-sm-12 search-collapse">
            <div class="select-list">
                <ul>
                    <li>
                        环保号牌：<input id="huanBaoCode" col="HuanBaoCode" type="text" />
                    </li>
                    <li>
                        <a id="btnSearch" class="btn btn-primary btn-sm" onclick="searchGrid()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                    </li>
                </ul>
            </div>
        </div>       
        <div class="col-sm-12 select-table table-striped">
            <div class="btn-group-sm hidden-xs" id="toolbar">
                <a id="btnAdd" class="btn btn-success" onclick="showSaveForm(true)"><i class="fa fa-plus"></i> 新增</a>
                <a id="btnEdit" class="btn btn-primary disabled" onclick="showSaveForm(false)"><i class="fa fa-edit"></i> 修改</a>
                <a id="btnDelete" class="btn btn-danger disabled" onclick="deleteForm()"><i class="fa fa-remove"></i> 删除</a>
            </div>
            <div class="row" id="plateList" style="margin-top:20px;">
            </div>
        </div>
    </div>
</div>
<style type="text/css">
    .plate {
        margin: 5px 25px;
        height: 70px;
        padding: 2px;
        border: 1px solid #288CE9;
    }

        .plate span {
            display:block;
            background-color: #288CE9;
            text-align: center;
            font-size: 40px;
            color: #fff;
            height: 64px;
            font-family: 宋体;
        }
</style>
<script type="text/javascript">
    $(function () {
        initGrid();
    });

    function initGrid() {
        var queryUrl = '@Url.Content("~/YiDongYuan/SparePlate/GetListJson")';
        ys.ajax({
            url: queryUrl + '?code=' + $("#huanBaoCode").val(),
                type: 'get',
            success: function (obj) {
                if (obj && obj.Data && obj.Data.length > 0) {
                    var html = '';
                    for (var i = 0; i < obj.Data.length; i++) {
                        html += '<div class="col-sm-2 plate"><span>'+obj.Data[i].HuanBaoCode+'</span></div>';
                    }
                    $("#plateList").empty();
                    $("#plateList").append(html);
                    }
                }
            });

    }

    function searchGrid() {
        initGrid();
    }

    function showSaveForm(bAdd) {
        var id = 0;
        if (!bAdd) {
            var selectedRow = $('#gridTable').bootstrapTable('getSelections');
            if (!ys.checkRowEdit(selectedRow)) {
                return;
            }
            else {
                id = selectedRow[0].Id;
            }
        }
        ys.openDialog({
            title: id > 0 ? '编辑' : '添加',
            content: '@Url.Content("~/YiDongYuan/SparePlate/SparePlateForm")' + '?id=' + id,
            width: '768px',
            height: '550px',
            callback: function (index, layero) {
                var iframeWin = window[layero.find('iframe')[0]['name']];
                iframeWin.saveForm(index);
            }
        });
    }

    function deleteForm() {
        var selectedRow = $('#gridTable').bootstrapTable('getSelections');
        if (ys.checkRowDelete(selectedRow)) {
            ys.confirm('确认要删除选中的' + selectedRow.length + '条数据吗？', function () {
                var ids = ys.getIds(selectedRow);
                ys.ajax({
                    url: '@Url.Content("~/YiDongYuan/SparePlate/DeleteFormJson")' + '?ids=' + ids,
                    type: 'post',
                    success: function (obj) {
                        if (obj.Tag == 1) {
                            ys.msgSuccess(obj.Message);
                            searchGrid();
                        }
                        else {
                            ys.msgError(obj.Message);
                        }
                    }
                });
            });
        }
    }
</script>
